<script lang="ts" setup>
import { reactive, ref } from 'vue'
import { tnNavPage } from '@tuniao/tnui-vue3-uniapp/utils'
import type { NavbarRectInfo } from '@tuniao/tnui-vue3-uniapp/components/navbar'
import PageContainer from '@/components/page-container/index.vue'
import user from '@/api/user.js'
import { FILE_URL } from '@/api/config.js'

const paging = ref(null)
const navbarHeight = ref(0)
// 导航栏初始化完毕
const navbarInitFinishHandle = (info: NavbarRectInfo) => {
  navbarHeight.value = info.height
}
const state = reactive({
  data: [],
  loading: false,
})

const queryList = (pageNo: any, pageSize: any) => {
  user
    .userJoinOb({
      page: pageNo,
      page_size: pageSize,
    })
    .then((res) => {
      paging.value.complete(res.data)
    })
    .catch((err) => {
      paging.value.complete(false)
    })
}
const navCirclesPostDetailPage = (circlesPostId: number) => {
  tnNavPage(`/circlesPostPages/detail?circlesPostId=${circlesPostId}`)
}
</script>

<template>
  <PageContainer :placeholder-bottom="true">
    <TnNavbar
      fixed
      :bottom-shadow="false"
      :placeholder="false"
      @init-finish="navbarInitFinishHandle"
    >
      我加入的组局
    </TnNavbar>
    <view class="page">
      <z-paging
        ref="paging"
        v-model="state.data"
        :paging-style="{ paddingTop: `${navbarHeight}px` }"
        @query="queryList"
      >
        <template #refresher="{ refresherStatus }">
          <CustomRefresher :status="refresherStatus" />
        </template>

        <view
          v-for="(item, index) in state.data"
          :key="index"
          @tap.stop="navCirclesPostDetailPage(item.circles_post_id)"
        >
          <view class="search-item tn-shadow">
            <view class="item-info">
              <view class="info-detail">
                <view class="title tn-text-ellipsis-2">
                  {{ item.circlesPost.content }}
                </view>
              </view>
              <view class="info-data">
                <view class="count-data">
                  <view class="count-item">
                    <view v-if="item.promoter == 1" style="color: #ffa726">
                      我发起的
                    </view>
                    <view v-else>我加入的</view>
                  </view>
                </view>
              </view>
            </view>
            <view v-if="item.first_image != ''" class="item-image">
              <image
                class="tn-image"
                :src="FILE_URL + item.first_image"
                mode="aspectFill"
              />
            </view>
          </view>
        </view>
      </z-paging>
    </view>
  </PageContainer>
</template>

<style lang="scss" scoped>
@use './styles/organizebureau.scss';
</style>
